/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.demo.controller;

import com.demo.service.RoleService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author serg
 */
@Controller
public class DefaultController {
    
    @Autowired
    RoleService roleService;

    @RequestMapping(value = "guest.htm", method = RequestMethod.GET)
	public ModelAndView guestHandler(
		HttpServletResponse httpServletResponse) {

		ModelAndView mav = new ModelAndView("guest");
		return mav;
	}
    
    @Secured({"ROLE_USER"})
	@RequestMapping(value = "staff.htm", method = RequestMethod.GET)
	public ModelAndView userHandler(
		HttpServletResponse httpServletResponse) {

		ModelAndView mav = new ModelAndView("user");
		return mav;
	}

    //@Secured({"ROLE_USER", "ROLE_ADMIN"})
    @RequestMapping(value = "admin.htm", method = RequestMethod.GET)
	public ModelAndView adminHandler(
		HttpServletResponse httpServletResponse) {

        List roles = roleService.getAll();
        ModelAndView mav = new ModelAndView("admin");
		mav.addObject("roles",roles);
        return mav;
	}
	
}

